import { GSprite } from "../../../../com/mui/controls/GSprite";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { Language } from "../../../../extend/language/Language";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { GTextFormat } from "../../../common/GTextFormat";
import { SecTimer } from "../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { RemainTimeTool } from "../award/RemainTimeTool";
import { RechargeData } from "../loginNotice/OpenRecharge/RechargeData";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
//class RechargeResTimePanel
    
    export  class RechargeResTimePanel extends GSprite
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createGImageBitmap(ImagesConst.RechargeGiftBagDesc, 0, 0, this);
            ObjCreate.createBg(0, 150, 260, 47, this, ImagesConst.RemainningTimeBg);
            ObjCreate.createGTextField(Language.getString(31325), 0, 150, 260, 30, this, GlobalStyle.getTextFormatCenter(GlobalStyle.textFormatGreen));
            var loc1=new GTextFormat("", 12, 16711680, true);
            this._resTimeTxt = ObjCreate.createGTextField("", 20, 167, 243, 30, this, loc1);
            this._secTimer = new SecTimer();
            this._secTimer.addListener(TimerType.ENTERFRAME, this.onTimerEnterFrameHandler);
            this._secTimer.addListener(TimerType.COMPLETE, this.onTimerCompleteHandler);
            return;
        }

        /* internal  */onTimerEnterFrameHandler(arg1: SecTimer): void
        {
            this._resTimeTxt.htmlText = Language.getString(30262) + RemainTimeTool.getRemainTimeByMillisecond(this._secTimer.repeatCount, "#ff0000", "#ffff00", 22);
            return;
        }

        /* internal  */onTimerCompleteHandler(arg1: SecTimer): void
        {
            arg1.stop();
            arg1.isDelete = false;
            return;
        }

        public updateResTime(): void
        {
            var loc1=RechargeData.restTime;
            this._secTimer.reset();
            this._secTimer.repeatCount = loc1;
            if (loc1 > 0) 
            {
                this._secTimer.start();
                this._resTimeTxt.htmlText = Language.getString(30262) + RemainTimeTool.getRemainTimeByMillisecond(this._secTimer.repeatCount, "#ff0000", "#ffff00", 22);
            }
            return;
        }

        public stopResTime(): void
        {
            this._secTimer.stop();
            this._secTimer.isDelete = false;
            return;
        }

        /* internal */ /* var */_resTimeTxt: GTextFiled;

        /* internal */ /* var */_secTimer: SecTimer;
    }
